package com.woniuxy.prescription.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.entity.Prescription;
import com.woniuxy.commons.utils.ResStatus;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.prescription.dao.PrescriptionDao;
import com.woniuxy.prescription.service.PrescriptionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Waves
 * @date 2022/6/8 14:05
 */
@Service
public class PrescriptionServiceImpl implements PrescriptionService {

    @Resource
    PrescriptionDao prescriptionDao;

    @Override
    public ResponseResult findAll(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Prescription> list = prescriptionDao.findAll();
        PageInfo<Prescription> pageInfo = PageInfo.of(list);

        return new ResponseResult(
                200,
                "查询成功",
                pageInfo,
                ResStatus.SUCCESS
        );
    }

    @Override
    public ResponseResult findByStatus(int currentPage, int pageSize, int keyPath) {
        PageHelper.startPage(currentPage,pageSize);
        List<Prescription> list = prescriptionDao.findByStatus(keyPath);
        PageInfo<Prescription> pageInfo = PageInfo.of(list);

        return new ResponseResult(
                200,
                "查询不同状态处方成功",
                pageInfo,
                ResStatus.SUCCESS
        );
    }

    @Override
    public ResponseResult batchDelete(int[] ids) {
        if(prescriptionDao.batchDelete(ids) > 0){
            return ResponseResult.SUCCESS;
        }
        return ResponseResult.Fail;
    }

    @Override
    public ResponseResult addOne(Prescription prescription) {
        if(prescriptionDao.addOne(prescription) > 0){
            return ResponseResult.SUCCESS;
        }
        return ResponseResult.Fail;
    }

    @Override
    public ResponseResult updateOne(Prescription prescription) {
        if(prescriptionDao.updateOne(prescription) > 0){
            return ResponseResult.SUCCESS;
        }
        return ResponseResult.Fail;
    }

    @Override
    public ResponseResult deleteOne(int id) {
        if(prescriptionDao.deleteOne(id) > 0){
            return ResponseResult.SUCCESS;
        }
        return ResponseResult.Fail;
    }

    @Override
    public ResponseResult findByContext(Prescription prescription) {
        return new ResponseResult(
                200,
                "查询处方成功",
                prescriptionDao.findByContext(prescription),
                ResStatus.SUCCESS
        );
    }

    @Override
    public ResponseResult findMedicineIdsByPid(int id) {
        return new ResponseResult(
                200,
                "查询药品数组id成功",
                prescriptionDao.findMedicineIdsByPid(id),
                ResStatus.SUCCESS
        );
    }

    @Override
    public ResponseResult findMedicine_Medicine(int[] ids) {
        return new ResponseResult(
                200,
                "查询药品使用详情成功",
                prescriptionDao.findMedicine_Medicine(ids),
                ResStatus.SUCCESS
        );
    }

    @Override
    public ResponseResult findById(int id) {
        return new ResponseResult(
                200,
                "查询处方成功",
                prescriptionDao.findById(id),
                ResStatus.SUCCESS
        );
    }

}
